package ch8;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;

public class MySocket1 {

	public static void main(String[] args) {
		try {
			ServerSocket st = new ServerSocket(6666);
			System.out.println("服务端启用成功！");
			while (true) {
				Socket s = st.accept();// 接收
				System.out.println("本地：" + s.getLocalAddress() + "端口：" + s.getLocalPort());
				System.out.println("远程：" + s.getInetAddress() + ",端口：" + s.getPort());
				InputStream in = s.getInputStream();
				// OutputStream out = s.getOutputStream();
				int ch = -1;
				while ((ch = in.read()) != -1) {
					System.out.print((char) ch);
				}
			}
		} catch (IOException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		}

	}

}
